<%@ page language="java" import="java.util.*" import="edu.colorado.karl.login.AccountManager"%>
<%@ include file="header.jspf"%>

<link rel="Stylesheet" type="text/css" media="Screen" charset="utf-8" href="css/common.css"/>

<html>
<head>
<title>IntelliCORE - Account Manager</title>
<link rel="stylesheet" type="text/css" media="screen" charset="utf-8" href="css/common.css"/>
</head>
<body><h1>Account Manager</h1>
<BR>Administrators can create, delete and maintain accounts here.<BR>
<BR>New accounts are automatically assigned the password "12345".
<BR>Users are strongly advised to change this immediately.<BR>
<BR>The account named "admin" cannot be modified or removed.<BR><BR>
<table border='1' cellspacing='8'>
  <tr>
    <th>Username</th>
    <th>Administrator</th>
    <th>Remove Account</th>
  </tr>
  <form action='save_account_changes.jsp' method='post'>

<%
AccountManager am = AccountManager.getAccountManager();
String nextName = "";
String checked = "";
boolean add_new = false;

userList = am.getUsers();
iter = userList.iterator();

//only administrators can view this page
if(access_level != 2)
{
%>

  <BR>Error, you must login to view this page.
  <meta http-equiv=REFRESH content=0;url=error_login_required.jsp>

<%
}

//iterate through the list of all accounts and print data for each
while(iter.hasNext())
{
  out.println("<tr><td align='center'>");
  nextName = (String)iter.next();
  out.println(nextName);
  out.println("</td><td align='center'>");

  //check if the user is an administrator
  if(nextName.compareTo("admin") != 0)
  {
    if(a.userIsAdmin(nextName))
    {
      checked = "checked";
    }
    else
    {
      checked = "";
    }
    out.println("<input type='checkbox' name='admin_change_" + nextName + "'" +  checked + ">");
  }
  out.println("</td><td align='center'>");

  //provide a remove option for every account except 'admin'
  if(nextName.compareTo("admin") != 0)
  {
    out.println("<input type='checkbox' name='remove_" + nextName + "'>");
  }
  out.println("</td></tr>");
}

//a new account is being added: create a new row in the table
if(am.getAddNew())
{
%>

  <tr>
    <td align='center'>
    <input type='text' name='new_acct_name' size='12' value='enter name' 
      style='background-color:yellow; font-weight:bold;'>
    </td>
    <td align='center'>
      <input type='checkbox' name='admin_new'>
    </td>
    <td align='center'>
      <input type='checkbox' name='cancel_new'>
    </td>
  </tr>

<%
}
%>

</table>
<BR><input type='submit' value='Save Changes'>
</form>
<form action='create_account.jsp' method='post'>
<input type='submit' value='Create New Account'>
</form>
</body></html>
